package net.mushystuff.dogalogue.services.pojo;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import net.mushystuff.dogalogue.beans.Breed;
import net.mushystuff.dogalogue.beans.Dog;
import net.mushystuff.dogalogue.daos.BreedDAO;
import net.mushystuff.dogalogue.daos.DogDAO;
import net.mushystuff.dogalogue.services.DogService;

public class DogServiceImpl implements DogService {
	
	private Log log = LogFactory.getLog(this.getClass());
	
	private BreedDAO breedDAO;
	
	private DogDAO dogDAO;
	
	@Required
	public void setBreedDAO(BreedDAO breedDAO) {
		this.breedDAO = breedDAO;
	}

	@Required
	public void setDogDAO(DogDAO dogDAO) {
		this.dogDAO = dogDAO;
	}

	public DogServiceImpl() {

	}

	@Transactional(readOnly=true)
	public Set<Breed> getAllBreeds() {
		log.info("Getting breeds");
		return new HashSet<Breed>(breedDAO.getAllBreeds());
	}

	@Transactional(readOnly=true)
	public List<Dog> getAllDogs() {
		log.info("Getting all dogs");
		return dogDAO.getAllDogs();
	}

	@Transactional(readOnly=true)
	public Dog getDog(String uuid) {
		return dogDAO.getDog(uuid);
	}

	@Transactional(readOnly=false)
	public void addDog(Dog dog) {
		dogDAO.saveDog(dog);
	}
}
